package com.zhang.publicproject.common.base;

import android.app.Application;
import android.content.Context;
import android.os.Handler;

import java.text.DecimalFormat;

public class MyApplication extends Application {

    public static Context mContext;
    private static Handler mHandler;
    private static long mMainThreadId;

    private static DecimalFormat mDf;
    public static String APP_NAME = "publicProject";
    public static boolean isDebug = true;

    /**
     * 得到上下文
     */
    public static Context getContext() {
        return mContext;
    }


    /**
     * 得到主线程的handler
     */
    public static Handler getHandler() {
        return mHandler;
    }


    public static DecimalFormat getDecimalFormat() {
        return mDf;
    }


    /**
     * 得到主线程的线程id
     */


    public static long getMainThreadId() {
        return mMainThreadId;
    }


    @Override
    public void onCreate() {// 程序的入口方法

        mDf = new DecimalFormat("#0.00");


        // 1.上下文
        mContext = getApplicationContext();

        // 2.主线程handler
        mHandler = new Handler();

        // 3.主线程的id
        mMainThreadId = android.os.Process.myTid();

        /**
         * Tid: thread
         * Pid: process
         * Uid: user
         */

        // mOkHttpClient   = new OkHttpClient();
        //    Picasso.setSingletonInstance(new Picasso.Builder(mContext).downloader(new OkHttpDownloader(getUnsafeOkHttpClient())).build());


        super.onCreate();
    }

/*
 public static OkHttpClient getUnsafeOkHttpClient() {

        try {
            // Create a trust manager that does not validate certificate chains
            final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                @Override
                public void checkClientTrusted(
                        java.security.cert.X509Certificate[] chain,
                        String authType) throws CertificateException {
                }

                @Override
                public void checkServerTrusted(
                        java.security.cert.X509Certificate[] chain,
                        String authType) throws CertificateException {
                }

                @Override
                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            }};

            // Install the all-trusting trust manager
            final SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts,
                    new java.security.SecureRandom());
            // Create an ssl socket factory with our all-trusting manager
            final SSLSocketFactory sslSocketFactory = sslContext
                    .getSocketFactory();

            OkHttpClient okHttpClient = new OkHttpClient();
            okHttpClient.setSslSocketFactory(sslSocketFactory);
            okHttpClient.setHostnameVerifier(new HostnameVerifier() {

                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;

                }
            });

            return okHttpClient;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
*/

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //   MultiDex.install(this);
    }
}
